package cn.myproject.user.service.impl;

import cn.myproject.user.domian.User;
import cn.myproject.user.mapper.UserMapper;
import cn.myproject.user.query.UserQuery;
import cn.myproject.user.service.IUserservice;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserserviceImpl implements IUserservice {
    @Autowired
    private UserMapper userMapper;
    //新增
    @Override
    public void addUser(User user) {
        userMapper.addUser(user);
    }
    //修改
    @Override
    public void updata(User user) {
        userMapper.updata(user);
    }
    //查询一个按照id
    @Override
    public User selectByid(Long id) {
        return userMapper.selectByid(id);
    }
    //分页查询
    @Override
    public PageInfo<User> selectAll(UserQuery userQuery) {
        PageHelper.startPage(userQuery.getCurrentPage(), userQuery.getPageSize());
        //按名字进行条件查询
        List<User> list = userMapper.selectbyName(userQuery);
        PageInfo<User> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
    //批量删除
    @Override
    public void delectall(List<Long> ids) {
        userMapper.delectall(ids);

    }
    //按id删除
    @Override
    public void delectByid(Long id) {
        userMapper.delectByid(id);
    }
}
